import request from '../utils/request';
import {stringify} from 'qs';
import {apiPrefix} from '../config/config';

export function create(params) {
  return request(`${apiPrefix}/posts`, {
    method: 'POST',
    body: params,
  });
}

export function getPage(params) {
  return request(`${apiPrefix}/post_page?${stringify(params)}`);
}

export function get(params) {
  return request(`${apiPrefix}/posts/${params}`);
}

export function update(params) {
  return request(`${apiPrefix}/posts/${params.id}`, {
    method: 'PUT',
    body: params.data,
  });
}

export function remove(params) {
  return request(`${apiPrefix}/posts/${params}`, {method: 'DELETE'});
}

export function removeByIds(params) {
  return request(`${apiPrefix}/post_delete_by_ids?ids=${params.ids.toString()}`, {method: 'DELETE'});
}
